package com.example.environment.controller;

import com.example.environment.pojo.Feedback;
import com.example.environment.pojo.Verification;
import com.example.environment.service.VerificationService;
import com.example.environment.tools.common.ResultMsg;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verification")
public class VerificationController {
    @Autowired
    private VerificationService verificationService;

    @PostMapping("/addVerification")
    public ResultMsg addFeedback(Verification verification,HttpServletRequest httpServletRequest) {
        if(httpServletRequest.getAttribute("id")==null){
            return ResultMsg.failOp("没有登录信息");
        }
        verification.setGsId(Integer.parseInt(httpServletRequest.getAttribute("id").toString()));
        //这里缺少对应反馈列表的分配更改
        return verificationService.addVerification(verification);
    }

    @GetMapping("/getAllVerificationById")
    public ResultMsg getAllVerificationById(HttpServletRequest httpServletRequest) {
        if(httpServletRequest.getAttribute("id")==null){
            return ResultMsg.failOp("没有登录信息");
        }
        return verificationService.getVerificationsByGsId(Integer.parseInt(httpServletRequest.getAttribute("id").toString()));
    }

    @PostMapping("/updateVerification")
    public ResultMsg updateVerification(Verification verification,HttpServletRequest httpServletRequest) {
        if(httpServletRequest.getAttribute("id")==null){
            return ResultMsg.failOp("没有登录信息");
        }
        return verificationService.updateVerification(verification,Integer.parseInt(httpServletRequest.getAttribute("id").toString()));
    }

    @GetMapping("/getVerificationList")
    public ResultMsg getVerificationList(HttpServletRequest httpServletRequest) {
//        if(httpServletRequest.getAttribute("id")==null){
//            return ResultMsg.failOp("没有登录信息");
//        }
        return verificationService.getVerificationList();
    }

    @GetMapping("/getVerifyStaByProvince")
    public ResultMsg getVerifyStaByProvince(HttpServletRequest httpServletRequest) {
//        if(httpServletRequest.getAttribute("id")==null){
//            return ResultMsg.failOp("没有登录信息");
//        }
        return verificationService.getVerifyStaByProvince();
    }

    @GetMapping("/getAqiStatsByMonth")
    public ResultMsg getAqiStatsByMonth(HttpServletRequest httpServletRequest) {
//        if(httpServletRequest.getAttribute("id")==null){
//            return ResultMsg.failOp("没有登录信息");
//        }
        return verificationService.getAqiStatsByMonth();
    }
    @GetMapping("/getVerificationStats")
    public ResultMsg getVerificationStats(HttpServletRequest httpServletRequest) {
//        if(httpServletRequest.getAttribute("id")==null){
//            return ResultMsg.failOp("没有登录信息");
//        }
        return verificationService.getVerificationStats();
    }



















}
